package com.dis.service.controller.admin;

import com.dis.common.annotation.CheckPermission;
import com.dis.pojo.dto.ChronicDiseaseDTO;
import com.dis.pojo.entity.ChronicDisease;
import com.dis.pojo.queryDTO.ChronicDiseasePageQueryDTO;
import com.dis.common.result.PageResult;
import com.dis.common.result.Result;
import com.dis.service.service.ChronicDiseaseService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/admin/chronic-disease")
@Api(tags = "慢性病管理接口")
@Slf4j
public class ChronicDiseaseController {

    @Autowired
    private ChronicDiseaseService chronicDiseaseService;

    /**
     * 新增慢性病
     * @param chronicDiseaseDTO
     * @return
     */
    @PostMapping
    @ApiOperation("新增慢性病")
    @CheckPermission("disease:add")
    public Result save(@RequestBody ChronicDiseaseDTO chronicDiseaseDTO) {
        log.info("新增慢性病：{}", chronicDiseaseDTO);
        chronicDiseaseService.save(chronicDiseaseDTO);
        return Result.success();
    }

    /**
     * 慢性病分页查询
     * @param chronicDiseasePageQueryDTO
     * @return
     */
    @GetMapping("/page/data")
    @ApiOperation("慢性病分页查询")
    @CheckPermission("disease:query")
    public Result<PageResult> pageData(ChronicDiseasePageQueryDTO chronicDiseasePageQueryDTO) {
        log.info("慢性病分页查询：{}", chronicDiseasePageQueryDTO);
        PageResult pageResult = chronicDiseaseService.pageQuery(chronicDiseasePageQueryDTO);
        return Result.success(pageResult);
    }

    /**
     * 慢性病分页查询
     * @param chronicDiseasePageQueryDTO
     * @return
     */
    @GetMapping("/page")
    @ApiOperation("慢性病分页查询")
    @CheckPermission("disease:query")
    public Result<PageResult> page(ChronicDiseasePageQueryDTO chronicDiseasePageQueryDTO) {
        log.info("慢性病分页查询：{}", chronicDiseasePageQueryDTO);
        PageResult pageResult = chronicDiseaseService.pageQuery(chronicDiseasePageQueryDTO);
        return Result.success(pageResult);
    }

    /**
     * 修改慢性病删除状态
     * @param status 状态 0-为删除 1-以删除
     * @param id 慢性病ID
     * @return
     */
    @PostMapping("/status/{status}")
    @ApiOperation("修改慢性病删除状态")
    @CheckPermission("disease:status")
    public Result updateStatus(@PathVariable Integer status, Long id) {
        log.info("修改慢性病状态：{}, {}", status, id);
        chronicDiseaseService.updateStatus(status, id);
        return Result.success();
    }

    /**
     * 根据ID查询慢性病
     * @param id
     * @return
     */
    @GetMapping("/{id}")
    @ApiOperation("根据ID查询慢性病")
    @CheckPermission("disease:query")
    public Result<ChronicDisease> getById(@PathVariable Long id) {
        log.info("根据ID查询慢性病：{}", id);
        ChronicDisease chronicDisease = chronicDiseaseService.getById(id);
        return Result.success(chronicDisease);
    }

    /**
     * 修改慢性病信息
     * @param chronicDiseaseDTO
     * @return
     */
    @PutMapping
    @ApiOperation("修改慢性病信息")
    @CheckPermission("disease:edit")
    public Result update(@RequestBody ChronicDiseaseDTO chronicDiseaseDTO) {
        log.info("修改慢性病信息：{}", chronicDiseaseDTO);
        chronicDiseaseService.update(chronicDiseaseDTO);
        return Result.success();
    }

    /**
     * 删除慢性病
     * @param id
     * @return
     */
    @DeleteMapping("/{id}")
    @ApiOperation("删除慢性病")
    @CheckPermission("disease:delete")
    public Result delete(@PathVariable Long id) {
        log.info("删除慢性病：{}", id);
        chronicDiseaseService.deleteById(id);
        return Result.success();
    }
    /**
     * 根据病种id查询所属的病种种类信息
     */
    @GetMapping("/type/{id}")
    @ApiOperation("根据病种id查询所属的病种种类信息")
    @CheckPermission("disease:query")
    public Result selectTypeInfo(@PathVariable Long id){
        return Result.success(chronicDiseaseService.selectTypeInfo(id));
    }
}
